package com.googlecode.cswish.struts.conversion;

import java.util.Map;

import org.apache.commons.lang.ClassUtils;

import com.googlecode.cswish.model.PropertyInfo;
import com.googlecode.cswish.struts.Invoker;

/**
 * The conversion information, used by PageConverter
 * 
 * @author feng Date: 2009-3-14
 */
public class ConversionContext {
	private String className;		// actionName
	private Object propertyValue;
	private PropertyInfo propertyInfo;
	private Invoker invoker;
	private int level;
	private String template;
	private Map context;
	
	public ConversionContext() {
	}
	
	public ConversionContext(String className, Object object, PropertyInfo propertyInfo,
			Invoker invoker, int level, String template, Map context) {
		this.className = className;
		this.propertyValue = object;
		this.propertyInfo = propertyInfo;
		this.invoker = invoker;
		this.level = level;
		this.template = template;
		this.context = context;
	}
	
	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}
	
	public Class getClassObject() {
		try {
			return ClassUtils.getClass(className);
		} catch (ClassNotFoundException ex) {
			return Object.class;
		}
	}

	public Object getObject() {
		return getPropertyValue();
	}

	public Object getPropertyValue() {
		return propertyValue;
	}
	public void setObject(Object object) {
		setPropertyValue(object);
	}

	public void setPropertyValue(Object object) {
		this.propertyValue = object;
	}
	public PropertyInfo getPropertyInfo() {
		return propertyInfo;
	}
	public void setPropertyInfo(PropertyInfo propertyInfo) {
		this.propertyInfo = propertyInfo;
	}
	public Invoker getInvoker() {
		return invoker;
	}
	public void setInvoker(Invoker invoker) {
		this.invoker = invoker;
	}
	public int getLevel() {
		return level;
	}
	public void setLevel(int level) {
		this.level = level;
	}
	public Map getContext() {
		return context;
	}
	public void setContext(Map context) {
		this.context = context;
	}
	public String getTemplate() {
		return template;
	}
	public void setTemplate(String template) {
		this.template = template;
	}

	public ConversionContext clone() {
		ConversionContext context = new ConversionContext();
		
		context.className = this.className;
		context.propertyValue = this.propertyValue;
		context.propertyInfo = this.propertyInfo;
		context.context = this.context;
		context.invoker = this.invoker;
		context.level = this.level;
		context.template = this.template;
		
		return context;
	}
}